package com.config.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class ZhimaOjWebMvcConfiguration implements WebMvcConfigurer {
    private final boolean letGo;
    @Autowired
    private TokenStore tokenStore;

    public ZhimaOjWebMvcConfiguration(boolean letGo) {
        this.letGo = letGo;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 所有的路径都要经过这个拦截器，没有token则不放行
        registry.addInterceptor(new ParseTokenInterceptor(tokenStore, letGo)).addPathPatterns("/**");
    }
}
